package packed_widgets

import "fyne.io/fyne/v2"

type TableColumn struct {
	Key                string
	Header             string                          // 列头文本内容
	GetText            func(interface{}) string        // 每行的对应列显示的文本内容
	Width              int                             // 每列宽度，表格每行内容不固定，只能固定宽度
	OrderBy            func(asc bool)                  // 点击header重新排序时调用
	GetIcon            func(interface{}) fyne.Resource // 图标
	DefaultOrderBy     bool                            // 默认排序列
	DoubleTappedExpand bool                            // 双击放大，会覆盖Table.OnDoubleTapped
}

func (column *TableColumn) SetKey(key string) *TableColumn {
	column.Key = key
	return column
}

func (column *TableColumn) SetHeader(header string) *TableColumn {
	column.Header = header
	return column
}

func (column *TableColumn) SetTextGetter(getText func(interface{}) string) *TableColumn {
	column.GetText = getText
	return column
}

func (column *TableColumn) SetWidth(width int) *TableColumn {
	column.Width = width
	return column
}

func (column *TableColumn) SetOrderBy(orderBy func(bool)) *TableColumn {
	column.OrderBy = orderBy
	return column
}

func (column *TableColumn) SetIconGetter(getIcon func(interface{}) fyne.Resource) *TableColumn {
	column.GetIcon = getIcon
	return column
}

func (column *TableColumn) SetDefaultOrder() *TableColumn {
	column.DefaultOrderBy = true
	return column
}

func (column *TableColumn) SetDoubleTappedExpand() *TableColumn {
	column.DoubleTappedExpand = true
	return column
}

func NewTableColumn() *TableColumn {
	return &TableColumn{}
}
